package com.py.androidUtils.UI.adapter;

import java.io.IOException;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.py.androidUtils.UI.utils.Bimp;
import com.py.androidUtils.base.BaseCommAdapter;
import com.readyidu.app.R;

/**
 * @说明
 * @作者 LY
 * @文件 SelectImagesAdapter.java
 * @时间 2015年7月21日 下午3:16:23
 */
public class SelectImagesAdapter extends BaseCommAdapter<String> {
	private LayoutInflater inflater;

	public SelectImagesAdapter(Context context) {
		inflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.common_select_image_item, null);
			holder.imageView = (ImageView) convertView.findViewById(R.id.images);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (listData.get(position) != null && ((String) listData.get(position)).trim().length() > 0) {
			try {
				Bitmap bitmap = Bimp.revitionImageSize((String) listData.get(position));
				holder.imageView.setImageBitmap(bitmap);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			holder.imageView.setImageResource(R.drawable.add_image);
		}
		return convertView;
	}

	private final class ViewHolder {
		private ImageView imageView;
	}
}
